private {
	import std.math;
}

public class Quaternion{
	float w	=	1.f;
	float x	=	.0f;
	float y	=	.0f;
	float z	=	.0f;

	this(){
	}

	this(float xx, float yy, float zz, float ang){
//		float ang = PI * (deg/180.f);
		float theta = sin(ang/2.f);

		w = cos( ang /2.f);
		x = xx * theta;
		y = yy * theta;
		z = zz * theta;
	}

	void createMatrix(float *matrix){
		matrix[0] = 1.f - 2.f * (y * y + z * z); 
		matrix[1] = 2.f * (x * y + z * w);
		matrix[2] = 2.f * (x * z - y * w);
		matrix[3] = .0f;  
		matrix[4] = 2.f * (x * y - z * w);  
		matrix[5] = 1.f - 2.f * (x * x + z * z); 
		matrix[6] = 2.f * (z * y + x * w);  
		matrix[7] = .0f;  
		matrix[8] = 2.f * (x * z + y * w);
		matrix[9] = 2.f * (y * z - x * w);
		matrix[10] = 1.f - 2.f * (x * x + y * y);  
		matrix[11] = .0f;  
		matrix[12] = .0f;  
		matrix[13] = .0f;  
		matrix[14] = .0f;  
		matrix[15] = 1.f;		
	}

	Quaternion multiply(Quaternion q){
		Quaternion res;
		res = new Quaternion;
	
		res.w = w*q.w - x*q.x - y*q.y - z*q.z;
		res.x = w*q.x + x*q.w + y*q.z - z*q.y;
		res.y = w*q.y + y*q.w + z*q.x - x*q.z;
		res.z = w*q.z + z*q.w + x*q.y - y*q.x;
		return res;
	}

	~this(){
	}
}
